package com.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.provider.dao.TProjectDao;
import com.provider.entity.*;
import com.provider.service.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 项目表(TProject)表服务实现类
 *
 * @author makejava
 * @since 2024-04-29 17:23:53
 */
@Service("tProjectService")
@Transactional(rollbackFor = Exception.class)
public class TProjectServiceImpl extends ServiceImpl<TProjectDao, TProject> implements TProjectService {

    @Resource
    TEpicService epicService;
    @Resource
    TStoryService storyService;

    @Resource
    TTaskService taskService;


    @Resource
    TProductTaskService productTaskService;

    @Resource
    TProductStoryService productStoryService;

    @Resource
    TProductEpicService productEpicService;


    @Override
    public List<TProject> queryAllProject() {
        LambdaQueryWrapper<TProject> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TProject::getIsValid, "Y");
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public List<String> queryAllKeys() {
        Set<String> set = new HashSet<>();

        LambdaQueryWrapper<TEpic> epicLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Set<String> collect = taskService.list().stream().map(TTask::getTaskId).collect(Collectors.toSet());
        Set<String> collect1 = storyService.list().stream().map(TStory::getStoryId).collect(Collectors.toSet());
        Set<String> collect2 = epicService.list().stream().map(TEpic::getEpicId).collect(Collectors.toSet());
        Set<String> collect3 = productTaskService.list().stream().map(TProductTask::getProductTaskId).collect(Collectors.toSet());
        Set<String> collect4 = productStoryService.list().stream().map(TProductStory::getProductStoryId).collect(Collectors.toSet());
        Set<String> collect5 = productEpicService.list().stream().map(TProductEpic::getProductEpicId).collect(Collectors.toSet());
        set.addAll(collect);
        set.addAll(collect1);
        set.addAll(collect2);
        set.addAll(collect3);
        set.addAll(collect4);
        set.addAll(collect5);
        return new ArrayList<>(set);
    }
}

